package com.franz.noteapp.ui.theme

import android.app.Activity
import android.os.Build
import androidx.compose.animation.animateColorAsState
import androidx.compose.animation.core.TweenSpec
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.*
import androidx.compose.ui.graphics.Color

private val DarkColorScheme = NoteColors(
    primary = Color.White,
    background = DarkGray,
    onBackground = Color.White,
    surface = LightBlue,
    onSurface = DarkGray,
    textColor = Color.Black
)

private val LightColorScheme = NoteColors(
    primary = Color.White,
    background = DarkGray,
    onBackground = Color.White,
    surface = LightBlue,
    onSurface = DarkGray,
    textColor = Color.Black
)

@Stable
class NoteColors(
    primary: Color,
    background: Color,
    onBackground: Color,
    surface: Color,
    onSurface: Color,
    textColor:Color
) {

    var primary: Color by mutableStateOf(primary)
        private set
    var background: Color by mutableStateOf(background)
        private set
    var onBackground: Color by mutableStateOf(onBackground)
        private set
    var surface: Color by mutableStateOf(surface)
        private set
    var onSurface: Color by mutableStateOf(onSurface)
        private set
    var textColor: Color by mutableStateOf(textColor)
        private set

}


private val LocalWeComposeColors = compositionLocalOf {
    DarkColorScheme
}

object NoteTheme {
    val colors: NoteColors
        @Composable
        get() = LocalWeComposeColors.current
    enum class Theme {
        Light, Dark
    }
}

@Composable
fun NoteAppTheme(
    darkTheme: Boolean = isSystemInDarkTheme(),
    theme: NoteTheme.Theme = NoteTheme.Theme.Dark,
    content: @Composable () -> Unit
) {

    val colorScheme = if (darkTheme) DarkColorScheme
    else when (theme) {
        NoteTheme.Theme.Light -> LightColorScheme
        else -> {
            DarkColorScheme
        }
    }

    val primary = animateColorAsState(colorScheme.primary, TweenSpec(600))
    val background = animateColorAsState(colorScheme.background, TweenSpec(600))
    val onBackground = animateColorAsState(colorScheme.onBackground, TweenSpec(600))
    val surface = animateColorAsState(colorScheme.surface, TweenSpec(600))
    val onSurface = animateColorAsState(colorScheme.onSurface, TweenSpec(600))
    val textColor = animateColorAsState(colorScheme.onSurface, TweenSpec(600))

    val colors = NoteColors(
        primary = primary.value,
        background = background.value,
        onBackground = onBackground.value,
        surface = surface.value,
        onSurface = onSurface.value,
        textColor = textColor.value
    )

    CompositionLocalProvider(LocalWeComposeColors provides colors) {
        MaterialTheme(
            typography = Typography,
            content = content
        )
    }
}